home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 December / Australian PC User - December 2003 (CD2).iso / software / apps / files / dwmx2k4.exe / Disk1 / data1.cab / Configuration_En / DataSources / ColdFusion / CFSTOREDPROC.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  8.8 KB  |  307 lines

  1. // Copyright 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2. var STOREDPROC_FILENAME = "SP_D.gif"
  3. var DATASOURCE_LEAF_FILENAME = "DSL_D.gif"
  4.  
  5.  
  6. //--------------------------------------------------------------------
  7. // FUNCTION:
  8. //   addDynamicSource
  9. //
  10. // DESCRIPTION:
  11. //   Displays the Stored Procedure Server Behavior dialog
  12. //
  13. // ARGUMENTS:
  14. //   none
  15. //
  16. // RETURNS:
  17. //   nothing
  18. //--------------------------------------------------------------------
  19.  
  20. function addDynamicSource()
  21. {
  22.   dw.popupServerBehavior("CFStoredProc.htm");
  23. }
  24.  
  25.  
  26. //--------------------------------------------------------------------
  27. // FUNCTION:
  28. //   findDynamicSource
  29. //
  30. // DESCRIPTION:
  31. //   Called by UD to locate instances of this data source on the page.
  32. //
  33. // ARGUMENTS:
  34. //   none
  35. //
  36. // RETURNS:
  37. //   array of objects with five properties: title, imageFile, allowDelete,
  38. //   dataSource, and name. 
  39. //--------------------------------------------------------------------
  40.  
  41. function findDynamicSources()
  42. {
  43.   var retList = new Array();
  44.   
  45.   var dom = dreamweaver.getDocumentDOM();
  46.   if (dom)
  47.   {
  48.     var fileURL = dom.URL;
  49.  
  50.     if (fileURL.length)
  51.     {
  52.       dwscripts.copyDesignNotesFromTempURL();
  53.     }
  54.     
  55.     var sbObjs = dwscripts.getServerBehaviorsByFileName("CFStoredProc.htm");
  56.     for (var i=0; i < sbObjs.length; i++)
  57.     {
  58.       var bAddDataSource = false;
  59.  
  60.       // Note that the recordset datasource will handle creating datasources
  61.       //   for recordsets returned from stored procs.
  62.  
  63.       // Add a datasource if the stored proc returns the status code.
  64.       var statusCodeVarName = sbObjs[i].getStatusCodeVarName();
  65.       if (statusCodeVarName)
  66.       {
  67.         bAddDataSource = true;
  68.       }
  69.       
  70.       // Add a datasource if the stored proc has any output variables.
  71.       var callParams = new Array();
  72.       sbObjs[i].getDatabaseCall(callParams);
  73.       if (callParams.length > 0 && !bAddDataSource)
  74.       {
  75.         for (var j = 0; !bAddDataSource && j < callParams.length; ++j)
  76.         {
  77.           var varType = callParams[j].varType.toUpperCase();
  78.           if (varType.indexOf("OUT") != -1)
  79.           {
  80.             bAddDataSource = true;
  81.           }
  82.         }
  83.       }
  84.       
  85.       if (bAddDataSource)
  86.       {
  87.         retList.push(new DataSource(sbObjs[i].getTitle(), STOREDPROC_FILENAME, 
  88.                      true, "CFSTOREDPROC.htm", ""));
  89.       }
  90.     }
  91.   }
  92.  
  93.   return retList;
  94. }
  95.  
  96.  
  97. //--------------------------------------------------------------------
  98. // FUNCTION:
  99. //   generateDynamicSourceBindings
  100. //
  101. // DESCRIPTION:
  102. //   Given a one of the title strings returned from findDynamicSource,
  103. //   this function returns the source bindings associated with that
  104. //   Stored Procedure.
  105. //
  106. // ARGUMENTS:
  107. //   sourceName - One of the title strings returned in findDynamicSource
  108. //
  109. // RETURNS:
  110. //   Returns a list of bindings for the given sourceName
  111. //--------------------------------------------------------------------
  112.  
  113. function generateDynamicSourceBindings(sourceName)
  114. {
  115.   var retList = new Array();
  116.  
  117.   // find the sbobj for the stored proc
  118.   var sbObjs = dwscripts.getServerBehaviorsByTitle(sourceName);
  119.   if (sbObjs && sbObjs.length)
  120.   {
  121.     // Add a binding for the status code if it is returned.
  122.     var statusCodeVarName = sbObjs[0].getStatusCodeVarName();
  123.     if (statusCodeVarName)
  124.     {
  125.       retList.push(new DataSourceBinding(statusCodeVarName, DATASOURCE_LEAF_FILENAME, 
  126.                                          false, "CFSTOREDPROC.htm", ""));
  127.     }
  128.     
  129.     // Add a binding for each 'out' or 'inout' parameter.
  130.     var callParams = new Array();
  131.     sbObjs[0].getDatabaseCall(callParams);
  132.     if (callParams.length > 0)
  133.     {
  134.       for (var j = 0; j < callParams.length; ++j)
  135.       {
  136.         var varType = callParams[j].varType.toUpperCase();
  137.         if (varType.indexOf("OUT") != -1)
  138.         {
  139.           retList.push(new DataSourceBinding(callParams[j].cfVarName, DATASOURCE_LEAF_FILENAME, 
  140.                                              false, "CFSTOREDPROC.htm", ""));
  141.         }
  142.       }
  143.     }
  144.   }
  145.  
  146.   return retList;
  147. }
  148.  
  149.  
  150. //--------------------------------------------------------------------
  151. // FUNCTION:
  152. //   generateDynamicDataRef
  153. //
  154. // DESCRIPTION:
  155. //   Returns a dynamic binding string for the given source and binding
  156. //
  157. // ARGUMENTS: 
  158. //   sourceName - the name of a data source
  159. //   bindingName - the name of a binding within that source
  160. //
  161. // RETURNS:
  162. //   Returns a dynamic binding string
  163. //--------------------------------------------------------------------
  164.  
  165. function generateDynamicDataRef(sourceName,bindingName,dropObject)
  166. {
  167.   var retVal = "";
  168.  
  169.   var sbObjs = dwscripts.getServerBehaviorsByTitle(sourceName);
  170.   if (sbObjs && sbObjs.length)
  171.   {
  172.     var paramObj = new Object();
  173.     paramObj.bindingName = bindingName;
  174.     retVal = extPart.getInsertString("", "CFStoredProc_DataRef", paramObj);
  175.  
  176.     // We need to strip the cfoutput tags if we are inserting into a CFOUTPUT tag
  177.     // or binding to the attributes of a ColdFusion tag.
  178.     if (dwscripts.canStripCfOutputTags(dropObject, true))
  179.     {
  180.       retVal = dwscripts.stripCFOutputTags(retVal, true);
  181.     } 
  182.   }
  183.       
  184.   return retVal;
  185. }
  186.  
  187.  
  188. //--------------------------------------------------------------------
  189. // FUNCTION:
  190. //   inspectDynamicDataRef
  191. //
  192. // DESCRIPTION:
  193. //   Inspects a dynamic binding string and returns a pair of 
  194. //   source and binding names.
  195. //
  196. // ARGUMENTS: 
  197. //   expression - a dynamic binding string
  198. //
  199. // RETURNS:
  200. //   An array of two items.
  201. //   The source name, and the binding name for the given string.
  202. //--------------------------------------------------------------------
  203.  
  204. function inspectDynamicDataRef(expression)
  205. {
  206.   var retVal = null; 
  207.  
  208.   if (expression.length)
  209.   {
  210.     var params = extPart.findInString("CFStoredProc_DataRef", expression);
  211.     
  212.     if (params)
  213.     {
  214.       // Find the original stored procedure that uses the output parameter
  215.       //   or the return status code variable refered to in this expression.
  216.       var sbObjs = dwscripts.getServerBehaviorsByFileName("CFStoredProc.htm");
  217.       var bFoundParent = false;
  218.       for (var i=0; !bFoundParent && i < sbObjs.length; i++)
  219.       {
  220.         // First check if it's an output parameter in the current sbObj.
  221.         var callParams = new Array();
  222.         sbObjs[i].getDatabaseCall(callParams);
  223.         for (var j = 0; !bFoundParent && j < callParams.length; ++j)
  224.         {
  225.           if (callParams[j].cfVarName.toUpperCase() == params.bindingName.toUpperCase())
  226.           {
  227.             // Note that it's possible two stored procedures reference the same 
  228.             //   output parameter. If this is the case, we'll just take the first.
  229.             bFoundParent = true;
  230.           }
  231.         }
  232.         
  233.         // If not found yet, it could be a reference to the returned status code
  234.         //   variable for the current sbObj.  
  235.         if (!bFoundParent)
  236.         {
  237.           var statusCodeVarName = sbObjs[i].getStatusCodeVarName();
  238.           if (   statusCodeVarName
  239.               && statusCodeVarName.toUpperCase() == params.bindingName.toUpperCase()
  240.              )
  241.           {
  242.             bFoundParent = true;
  243.           }
  244.         }      
  245.  
  246.         // Build return array if we've found the correct stored proc object.
  247.         if (bFoundParent)
  248.         {
  249.           retVal = new Array();
  250.           retVal[0] = sbObjs[i].getTitle();
  251.           retVal[1] = params.bindingName;
  252.         }
  253.       }
  254.     }          
  255.   }
  256.   
  257.   return retVal;
  258. }
  259.  
  260.  
  261. //--------------------------------------------------------------------
  262. // FUNCTION:
  263. //   deleteDynamicSource
  264. //
  265. // DESCRIPTION:
  266. //   Deletes a dynamic source from the document.
  267. //
  268. // ARGUMENTS:
  269. //   sourceName - a data source name
  270. //   bindingName - one of the bindings for that data source
  271. //
  272. // RETURNS:
  273. //   nothing
  274. //--------------------------------------------------------------------
  275.  
  276. function deleteDynamicSource(sourceName,bindingName)
  277. {
  278.   var sbObjs = dwscripts.getServerBehaviorsByTitle(sourceName);
  279.  
  280.   if (sbObjs.length > 0 && !bindingName)
  281.   {
  282.     // Warn the user that this operation will delete the recordset datasource
  283.     //   that is returned from this stored proc. Make sure this is the desired
  284.     //   action.
  285.     var returnedRSName = sbObjs[0].getRecordsetName();
  286.     var continueDelete = true;
  287.     if (returnedRSName)
  288.     {
  289.       var displayName = dwscripts.getRecordsetDisplayName();
  290.       continueDelete = confirm(dwscripts.sprintf(MM.MSG_WarnDeleteReturnedRS, 
  291.                                                  displayName,
  292.                                                  returnedRSName,
  293.                                                  displayName));
  294.     }
  295.     
  296.     if (continueDelete)
  297.     {
  298.       dw.serverBehaviorInspector.deleteServerBehavior(sbObjs[0]);
  299.     }
  300.   }
  301.   else if (bindingName) 
  302.   {
  303.     alert(MM.MSG_CantDelColumn);
  304.   }
  305. }
  306.  
  307.